li r1, 10
li r13, 50
li r3, 100

li r6, 0  // outer loop counter  r6=j
li r7, 0  // inner loop counter  r7=i 

mv r12, r14
addi r12, -1     // r12 has N-1

OUTERLOOP1:
mv r8,r12
sub r8,r6       // (N-1) -j >0
blez r8, ENDOUTERLOOP1 

li r11, 0    // y(j)  = 0
li r7, 0      // inner loop counter
mv r2,r6
add r2,r13      // index of array x starts at j and decreases
li r1, 0       // initialize i as 0 each time for H(i)
li r1, 10
INNERLOOP1:
mv r8,r6
sub r8,r7        // while j-i >=0 .. 
blz r8, ENDINNERLOOP1


load r4, 0(r1)
load r5, 0(r2)
mv r9,r4
mul r9, r5    // y(j) = y(j) + h(i)* x(j-i)
add r11, r9


addi r1, 1    // incrementing the H array address
addi r2, -1   // decrementing the x array address


addi r7, 1

bez r0, INNERLOOP1
ENDINNERLOOP1:
store r11, 0(r3)  
addi r3,1


addi r6, 1
bez r0, OUTERLOOP1
ENDOUTERLOOP1:

//********j= N-1 to M-1**********************

li r1, 0
li   r1, 10
mv r12,r15
addi r12,-1     // r12 has M-1

OUTERLOOP2:

mv r8,r12
sub r8, r6
blez r8, ENDOUTERLOOP2 

li r11, 0     // y(j)  = 0
li r7, 0      // inner loop counter
mv r2,r6
add r2, r13      // index of array x starts at j and decreases
li r1,0       // initialize i as 0 each time for H(i)
li r1, 10
INNERLOOP2:
mv r8,r14
sub r8, r7       //  N > i
blez r8, ENDINNERLOOP2 

load r4, 0(r1)
load r5, 0(r2)
mv r9,r4
mul r9, r5    // y(j) = y(j) + h(i)* x(j-i)
add r11, r9


addi r1,1  // incrementing the H array address
addi r2,-1  // decrementing the x array address


addi r7, 1

bez r0, INNERLOOP2
ENDINNERLOOP2:
store r11, 0(r3)
addi r3, 1


addi r6,1
bez r0, OUTERLOOP2
ENDOUTERLOOP2:

//****** j= M-1 to M+N-1***************

mv r12,r14
add r12,r15
addi r12, -1     // r12 has M+N-1

OUTERLOOP:

mv r8,r12
sub r8,r6   // (N+M-1) - j  > 0
blez r8, ENDOUTERLOOP 

li r11, 0     // y(j)  = 0
mv r7,r6
sub  r7, r15    
addi r7, 1      // r7 contains j-M+1
li r1, 0
li   r1, 10
add  r1, r7      // index of  H = 10 + (j-M+1)

mv r2,r15
addi  r2,-1     // index of X = j-i starts at M-1 each time
add  r2, r13       


INNERLOOP:
mv r8,r14
sub r8,r7       // 
blez r8, ENDINNERLOOP 
 

load r4, 0(r1)
load r5, 0(r2)
mv r9,r4
mul r9, r5    // y(j) = y(j) + h(i)* x(j-i)
add r11, r9


addi r1, 1  // incrementing the H array address
addi r2, -1  // decrementing the x array address


addi r7,1
bez r0, INNERLOOP
ENDINNERLOOP:

store r11, 0(r3)
addi r3, 1


addi r6,1
bez r0, OUTERLOOP

ENDOUTERLOOP: